home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
ast_comp
/
yyref.shr
< prev
Wrap
Text File
|
1993-07-04
|
12KB
|
684 lines
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 11/06/1991 21:23 UTC by johnl@iecc
# Source directory /usr/johnl/News
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 221 -rw-r--r-- yyref/Makefile
# 4607 -rw-r--r-- yyref/yyref-grammar
# 2697 -rw-r--r-- yyref/yyref-lex
# 1806 -rw-r--r-- yyref/yyref.1
#
# ============= yyref/Makefile ==============
if test ! -d 'yyref'; then
echo 'x - creating directory yyref'
mkdir 'yyref'
fi
if test -f 'yyref/Makefile' -a X"$1" != X"-c"; then
echo 'x - skipping yyref/Makefile (File already exists)'
else
echo 'x - extracting yyref/Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'yyref/Makefile' &&
X
CFLAGS=
yyref: yyref-lex yyref-grammar
X lex yyref-lex
X yacc -vd yyref-grammar
X cc $(CFLAGS) y.tab.c -o yyref
X
clean:
X rm -f lex.yy.c y.tab.? y.output
X
force: yyref-lex yyref-grammar
X touch yyref-lex yyref-grammar
X make
X
SHAR_EOF
chmod 0644 yyref/Makefile ||
echo 'restore of yyref/Makefile failed'
Wc_c="`wc -c < 'yyref/Makefile'`"
test 221 -eq "$Wc_c" ||
echo 'yyref/Makefile: original size 221, current size' "$Wc_c"
fi
# ============= yyref/yyref-grammar ==============
if test -f 'yyref/yyref-grammar' -a X"$1" != X"-c"; then
echo 'x - skipping yyref/yyref-grammar (File already exists)'
else
echo 'x - extracting yyref/yyref-grammar (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'yyref/yyref-grammar' &&
%{
X
# include <ctype.h>
X
int line;
%}
X
X
X /*******************************************************\
X * *
X * X_reference program for YACC files *
X * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
X * *
X * Cathy Taylor, *
X * c/o Department of Computing, *
X * University of Lancaster, *
X * Bailrigg, Lancaster, England. *
X * Date : Fri Jul 4 00:50:04 BST 1986 *
X * *
X \*******************************************************/
X
X
X /***********************************************\
X * *
X * Yacc Input Syntax *
X * ~~~~~~~~~~~~~~~~~ *
X * *
X * Adapted from the document *
X * 'YACC - Yet Another Compiler Compiler' *
X * by *
X * S. C. Johnson *
X * *
X * Date: Tue Jul 1 02:40:18 BST 1986 *
X * *
X \***********************************************/
X
X
%token IDENTIFIER CHARACTER NUMBER
%token LEFT RIGHT NONASSOC TOKEN PREC TYPE START UNION
%token PER PERCURL ACT
%token COLON SEMICOLON COMMA OR LESS GREATER
X
%start spec
X
%%
X
spec
X : defs PER rules tail
X {
X printf("\n\n");
X yyclearin;
X return(0);
X }
X ;
X
tail
X : /* empty */
X | PER
X | error
X ;
X
defs
X : /* empty */
X | def_bk
X ;
X
def_bk
X : def
X | def_bk def
X ;
X
def
X : START IDENTIFIER
X | UNION
X | PERCURL
X | rword tag nlist
X | tokendef
X | error
X ;
X
rword
X : LEFT
X | RIGHT
X | NONASSOC
X | TYPE
X ;
X
tokendef
X : TOKEN tokenlist
X ;
X
tokenlist
X : IDENTIFIER
X {
X yyaction(ON_C_IDENT,line);
X }
X | tokenlist opt_comma IDENTIFIER
X {
X yyaction(ON_C_IDENT,line);
X }
X ;
tag
X : /* empty */
X | LESS IDENTIFIER GREATER
X ;
X
nlist
X : nmno
X | nlist opt_comma nmno
X ;
X
opt_comma
X : /* empty */
X | COMMA
X ;
X
nmno
X : IDENTIFIER opt_num
X ;
X
opt_num
X : /* empty */
X | NUMBER
X ;
rules
X : rule
X | rules rule
X ;
X
rule
X : IDENTIFIER
X {
X yyaction(ON_C_IDENT,line);
X }
X COLON body SEMICOLON
X | error SEMICOLON
X ;
X
body
X : body_block
X | body OR body_block
X ;
X
body_block
X : /* empty */
X | body_block body_entity
X ;
X
body_entity
X : opt_prec id_ent
X | ACT
X ;
X
id_ent
X : IDENTIFIER
X {
X yyaction(ON_IDENT,line);
X }
X | CHARACTER
X ;
X
opt_prec
X : /* empty */
X | PREC
X ;
X
X
%%
X
# include "lex.yy.c"
X
#define ON_C_IDENT 000
#define ON_IDENT 001
X
#define MAXIDENTS 1000
#define MAXCHARS 100
#define MAXDEFS 20
#define MAXOCCS 1000
X
struct IREC {
X char ident[MAXCHARS];
X int desc[MAXDEFS];
X int nextdesc;
X int occ[MAXOCCS];
X int nextocc;
X } table[MAXIDENTS];
X
X
yyaction (action,ln)
int action;
int ln;
{
X int id;
X
X id = 0;
X while ( strcmp(table[id].ident,yytext) != 0 && strcmp(table[id].ident,"") != 0 )
X id++;
X
X if ( strcmp(table[id].ident, yytext) != 0 )
X {
X
X /*******************************************************\
X * *
X * New non-terminal to be stored. *
X * No distinction is made here between tokens *
X * and (non) terminals. *
X * *
X \*******************************************************/
X
X strcpy(table[id].ident,yytext);
X table[id].nextdesc = 0;
X table[id].nextocc = 0;
X } /* fi */
X
X switch (action) {
X case ON_C_IDENT:
X
X /*******************************************************\
X * *
X * Add to list of definition lines. *
X * *
X \*******************************************************/
X
X table[id].desc[table[id].nextdesc++] = ln;
X break;
X
X case ON_IDENT:
X
X /*******************************************************\
X * *
X * Add to list of occurance lines. *
X * *
X \*******************************************************/
X
X table[id].occ[table[id].nextocc++] = ln;
X break;
X
X default :
X fprintf (stdout, "yyaction: invalid action\n");
X return (-1);
X } /* hctiws */
X return (0);
} /* corp */
X
nline(ln)
int ln;
{
X printf("%4d :\t",ln);
}
X
X
X char declared_at_mark[] = "*";
X char occurs_at_mark[] = "";
X char token_maybe[] = "is not declared";
X char start_maybe[] = "never occurs on rhs of rule - start rule?";
X
/*
* Strings for output
*/
X
main ()
{
X int ind,id;
X
X strcpy(table[0].ident,"");
X
X line = 0;
X nline(++line);
X
X yyparse ();
X
X printf("\n\n~~~~~ Start of X-ref ~~~~~\n");
X id = 0;
X while( strcmp(table[id].ident,"") != 0 )
X {
X printf("\n%-20s ",table[id].ident);
X if (table[id].nextdesc == 0 )
X printf(" : %s",token_maybe);
X else
X {
X ind = 0;
X printf("%4d:",table[id].desc[ind++]);
X for ( ind=1; ind < table[id].nextdesc ; ind++)
X printf(" %s%4d",declared_at_mark,table[id].desc[ind]);
X }
X if (table[id].occ[0] == 0)
X printf(" %s",start_maybe);
X else
X {
X for ( ind = 0; ind < table[id].nextocc ; ind++ )
X printf(" %s%4d",occurs_at_mark,table[id].occ[ind]);
X }
X id++;
X }
X printf("\n\n~~~~~ End of X-ref ~~~~~\n");
} /* niam */
X
yyerror(mess)
char *mess;
{
X printf("\n\t%s\n",mess);
} /* corp */
SHAR_EOF
chmod 0644 yyref/yyref-grammar ||
echo 'restore of yyref/yyref-grammar failed'
Wc_c="`wc -c < 'yyref/yyref-grammar'`"
test 4607 -eq "$Wc_c" ||
echo 'yyref/yyref-grammar: original size 4607, current size' "$Wc_c"
fi
# ============= yyref/yyref-lex ==============
if test -f 'yyref/yyref-lex' -a X"$1" != X"-c"; then
echo 'x - skipping yyref/yyref-lex (File already exists)'
else
echo 'x - extracting yyref/yyref-lex (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'yyref/yyref-lex' &&
X
X /*******************************************************\
X * *
X * X_ref for YACC - LEX file *
X * ~~~~~~~~~~~~~~~~~~~~~~~~~ *
X * Date: Tue Jul 1 03:36:21 BST 1986 *
X * *
X \*******************************************************/
X
%{
X
#define TRUE 1
#define FALSE 0
X
int recognised;
int scope;
char c, lastchar, thischar;
X
%}
X
X /* abbreviations */
X
digit [0-9]
u_case [A-Z]
l_case [a-z]
id_char [A-Za-z0-9_\.]
letter [A-Za-z\._]
white [\t ]
X
X
%%
X
"/*" {
X ECHO;
X recognised = FALSE;
X c = nextchar();
X while (recognised == FALSE)
X {
X while (c != '*')
X c = nextchar();
X c = nextchar();
X if (c == '\/')
X recognised = TRUE;
X }
X }
"%{" {
X ECHO;
X recognised = FALSE;
X c = nextchar();
X while (recognised == FALSE)
X {
X while (c != '\%')
X c = nextchar();
X c = nextchar();
X if (c == '\}')
X recognised = TRUE;
X }
X return(PERCURL);
X }
"{" {
X
/*
* Although LEX can cope with the full definition,
* ( "{"[^\}]*"}" ) this may overrun the lex buffer (200 chars).
* Thus this routine.
*/
X
X ECHO;
X c = nextchar();
X scope = 1;
X while (scope > 0)
X {
X c = nextchar();
X switch (c)
X {
X case '*':
X if (lastchar == '/')
X do
X c = nextchar();
X while ((lastchar != '*') || (c != '/'));
X break;
X case '"':
X do
X c = nextchar();
X while ((lastchar == '\\') || (c != '"'));
X break;
X case '{':
X scope++;
X break;
X case '}':
X scope--;
X break;
X default:
X break;
X }
X }
X return(ACT);
}
X
X
X
{letter}{id_char}* {
X ECHO;
X return(IDENTIFIER);
X }
"'"(\\.|[^'])+"'" {
X ECHO;
X return(CHARACTER);
X }
{white}+ {
X ECHO;
X }
{digit}+ {
X ECHO;
X return(NUMBER);
X }
"%"{white}*"left" {
X ECHO;
X return(LEFT);
X }
"%"{white}*"right" {
X ECHO;
X return(RIGHT);
X }
"%"{white}*"nonassoc" {
X ECHO;
X return(NONASSOC);
X }
"%"{white}*"token" {
X ECHO;
X return(TOKEN);
X }
"%"{white}*"prec" {
X ECHO;
X return(PREC);
X }
"%"{white}*"type" {
X ECHO;
X return(TYPE);
X }
"%"{white}*"start" {
X ECHO;
X return(START);
X }
"%"{white}*"union" {
X ECHO;
X return(UNION);
X }
"%%" {
X ECHO;
X return(PER);
X }
":" {
X ECHO;
X return(COLON);
X }
";" {
X ECHO;
X return(SEMICOLON);
X }
"," {
X ECHO;
X return(COMMA);
X }
"|" {
X ECHO;
X return(OR);
X }
"<" {
X ECHO;
X return(LESS);
X }
">" {
X ECHO;
X return(GREATER);
X }
"\n" {
X ECHO;
X nline(++line);
X }
X
%%
X
yywrap()
{
X /* wrap-up procedure */
X return(1);
}
X
nextchar()
{
X char c;
X
X c = input();
X printf("%c",c);
X if (c == '\n')
X nline(++line);
X lastchar = thischar;
X thischar = c;
X return(c);
}
SHAR_EOF
chmod 0644 yyref/yyref-lex ||
echo 'restore of yyref/yyref-lex failed'
Wc_c="`wc -c < 'yyref/yyref-lex'`"
test 2697 -eq "$Wc_c" ||
echo 'yyref/yyref-lex: original size 2697, current size' "$Wc_c"
fi
# ============= yyref/yyref.1 ==============
if test -f 'yyref/yyref.1' -a X"$1" != X"-c"; then
echo 'x - skipping yyref/yyref.1 (File already exists)'
else
echo 'x - extracting yyref/yyref.1 (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'yyref/yyref.1' &&
.TH YYREF 1 LOCAL
.SH NAME
yyref \- generate cross\-reference for YACC input
.SH SYNOPSIS
.B yyref
[ < inputfile ]
.SH DESCRIPTION
.I Yyref
generates cross\-references for
.IR yacc (1)
input files.
It reads source from standard input, and upon EOF or seeing the second
.B %%
that marks the end of the rules portion, generates a cross\-reference
list of all parser tokens.
.PP
In case of syntax errors in the input,
.I yyref
tries to generate as much information as it can.
.PP
The output consists of a number listing of the header and rules part,
followed by the cross\-reference:
.RS
.nf
X 1 : %{
X 2 : # include <ctype.h>
X 3 : %}
X 4 :
X 5 :
X 6 : /*******************************************************\
X 7 : * *
X 8 : * Date : Fri Jul 4 00:50:04 BST 1986 *
X 9 : * *
X 10 : \*******************************************************/
X 11 :
X 12 : %token IDENTIFIER START_TOKEN NUMBER
X 13 :
X 14 : %start small
X 15 :
X 16 : %%
X 17 :
X 18 : small
X 19 : : start middle
X 20 : {
X 21 : printf("\n\nMiddle");
X 22 : yyclearin;
X 23 : return(0);
X 24 : }
X 25 : end postamble
X 26 : ;
X 27 :
X 28 : start
X 29 : : /* empty */
X 30 : | START_TOKEN
X 31 : ;
X 32 :
X 33 : middle
X 34 : :
X 35 : ;
X 36 :
X 37 : middle
X 38 : : MID_TOKEN
X 39 : | /* empty */
X 40 : ;
X 41 :
X 42 : %%
X
X
'small' -
~~~~~~~ *18 , never occurs on rhs of rule - start rule?
'start' -
~~~~~~~ *28 , 19
'middle' -
~~~~~~~ *33 , *37, 19
'end' -
~~~~~~~ is not declared - token??, 25
'postamble' -
~~~~~~~ is not declared - token??, 25
'START_TOKEN' -
~~~~~~~ is not declared - token??, 30
'MID_TOKEN' -
~~~~~~~ is not declared - token??, 38
X
X End of X-ref
X ~~~~~~~~~~~~
.fi
.RE
.SH BUGS
Should be able to understand the
.I %token
and similar directives.
SHAR_EOF
chmod 0644 yyref/yyref.1 ||
echo 'restore of yyref/yyref.1 failed'
Wc_c="`wc -c < 'yyref/yyref.1'`"
test 1806 -eq "$Wc_c" ||
echo 'yyref/yyref.1: original size 1806, current size' "$Wc_c"
fi
exit 0